<?php 
class ContentModel extends ViewModel{
	public $table='content';

	public $view=array(
		'content'=>array('_type'=>'INNER','_as'=>'cc'),
		'category'=>array('_on'=>'cc.cid=category.cid'),
	);

	public $auto=array(
		array('addtime','strtotime','function',2,3),
		array('thumb','_autoThumb','method',2,3)
	);

	public function _autoThumb($v){
		if(empty($v)) return $v;
		$v=current($v);
		return $v['path'];
	}

	public function getList(){
		$count=$this->count();		
		$page=new Page($count,3);
		$data=$this->limit($page->limit())->all();
		return array('data'=>$data,'page'=>$page->show());		
	}

	public function addContent(){
		if($this->create()){
			if($this->add()){
				return true;
			}else{
				$this->error='添加失败';
			}
		}
	}

	public function editContent(){
		if($this->create()){
			if($this->save()){
				return true;
			}else{
				return $this->error='编辑失败';
			}
		}
	}

	public function deleteContent($aid){
		if($this->create()){
			if($this->where("aid={$aid}")->del()){
				return true;
			}else{
				$this->error='删除失败';
			}
		}
	}


}

?>